//
//  TeaStudentViewController.m
//  LoveDraw
//
//  Created by 零零壹 on 2017/9/23.
//  Copyright © 2017年 梁晨. All rights reserved.
//

#import "TeaStudentViewController.h"
#import "TeaStuHeadTableViewCell.h"
#import "MySignTableViewCell.h"
#import "TeaStuLessonInfoTableViewCell.h"
@interface TeaStudentViewController ()<UITableViewDelegate,UITableViewDataSource,TeaStuHeadTableViewCellDelegate>
@property(nonatomic,strong)NSDictionary *infoDic;
@property(nonatomic,strong)UITableView *listV;
@property(nonatomic,strong)NSMutableArray *listArr;
@end

@implementation TeaStudentViewController
{
    NSInteger page;
}

-(NSMutableArray *)listArr
{
    if (!_listArr) {
        _listArr = [NSMutableArray array];
    }
    return _listArr;
}
-(UITableView *)listV
{
    if (!_listV) {
        _listV = [[UITableView alloc]initWithFrame:CGRectMake(0, -20, KscreenW, KscreenH+20) style:(UITableViewStyleGrouped)];
        _listV.delegate = self;
        _listV.dataSource = self;
        _listV.separatorStyle = 0;
        _listV.estimatedSectionFooterHeight = 0;
        _listV.estimatedSectionHeaderHeight = 0;
        [_listV registerNib:[UINib nibWithNibName:@"TeaStuHeadTableViewCell" bundle:nil] forCellReuseIdentifier:@"TeaStuHeadTableViewCell"];
        [_listV registerClass:[MySignTableViewCell class] forCellReuseIdentifier:@"mysigncell"];
        [_listV registerClass:[TeaStuLessonInfoTableViewCell class] forCellReuseIdentifier:@"TeaStuLessonInfoTableViewCell"];
//        [_listV registerNib:[UINib nibWithNibName:@"TeaStuLessonInfoTableViewCell" bundle:nil] forCellReuseIdentifier:@"TeaStuLessonInfoTableViewCell"];

    }
    return _listV;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 220;
    }else if (indexPath.section == 1)
    {
       return   [self.infoDic[@"classhour_total"] integerValue]/10.0*(KscreenW-60)/10+16+20;
    }
    else
    {
        return 80;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 2) {
        return 40;
    }else
    {
        return FLT_MIN;
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 2)
    {
        UIView *headV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KscreenW, 40)];
        headV.backgroundColor = [UIColor whiteColor];

        UILabel *titleL = [[UILabel alloc]init];
        titleL.text = @"点名记录";
        titleL.font = [UIFont systemFontOfSize:15 weight:UIFontWeightBold];
        [headV addSubview:titleL];
        [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(headV.mas_centerX);
            make.centerY.equalTo(headV.mas_centerY);
        }];

        UIImageView *line1 = [[UIImageView alloc]init];
        line1.image = [UIImage imageNamed:@"left_line"];
        [headV addSubview:line1];

        UIImageView *line2 = [[UIImageView alloc]init];
        line2.image = [UIImage imageNamed:@"right_line"];
        [headV addSubview:line2];

        [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(titleL.mas_left).offset(-5);
            make.centerY.equalTo(titleL.mas_centerY);
        }];

        [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(titleL.mas_right).offset(5);
            make.centerY.equalTo(titleL.mas_centerY);
        }];

        return headV;
    }else
    {
        return nil;
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else if (section == 2)
    {
        return self.listArr.count;
    }else
    {
        return 1;
    }
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {

        TeaStuHeadTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TeaStuHeadTableViewCell" forIndexPath:indexPath];
        cell.Delegate = self;
        [cell.headImageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KUrl,self.infoDic[@"lifethumb"]]] placeholderImage:nil];
        if ([self.infoDic[@"sex"]isEqualToString:@"男"]) {
            cell.seximage.image = [UIImage imageNamed:@"man"];
        }else
        {
            cell.seximage.image = [UIImage imageNamed:@"women"];
        }
        cell.NameL.text = self.infoDic[@"name"];
        cell.birthday.text = self.infoDic[@"birthday"];
        cell.nickName.text = self.infoDic[@"nickname"];
        cell.LianXiRen.text = self.infoDic[@"specialman"];
        cell.phoneL.text = self.infoDic[@"telphone"];
        cell.addtime.text = self.infoDic[@"join_date"];
        cell.selectionStyle = 0;
        return cell;
    }else if (indexPath.section == 2)
    {
        /*
         @property(nonatomic,strong)UILabel *leftYear;
         @property(nonatomic,strong)UILabel *leftMonth;
         @property(nonatomic,strong)UILabel *titleLabel;
         @property(nonatomic,strong)UILabel *statusLabel;
         @property(nonatomic,strong)UILabel *remarkLabel;
         */
        NSDictionary *dataDic = self.listArr[indexPath.row];
        MySignTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mysigncell" forIndexPath:indexPath];
        cell.leftYear.text = dataDic[@"date_year"];
        cell.leftMonth.text = dataDic[@"date_md"];
        cell.titleLabel.text = dataDic[@"coursename"];
        cell.remarkLabel.text = dataDic[@"description"];
        cell.leftImage.image = [UIImage imageNamed:@"round"];
        cell.selectionStyle = 0;
        if (indexPath.row  == 0) {
            [cell.lineView setHidden:YES];
        }else
        {
            [cell.lineView setHidden:NO];
        }

        if (indexPath.row  == self.listArr.count-1) {
            [cell.bottomLineV setHidden:YES];
        }else
        {
            [cell.bottomLineV setHidden:NO];
        }
        return cell;
    }else
    {
        TeaStuLessonInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TeaStuLessonInfoTableViewCell" forIndexPath:indexPath];
        cell.infoDic = self.infoDic;
        [cell.MineCollectionV reloadData];
        [cell setCollectVFrame];
        cell.selectionStyle = 0;
        return cell;
    }
 
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view addSubview:self.listV];
    page = 1;
    [self Request];
    [self recordRequest];
}

-(void)Request
{
    [RequestManager RequstWithUrl:@"/index.php?g=App&m=TeacherCourse&a=courseStudentdetail" parmDic:@{@"aid":self.aid} requestType:RequestGET Success:^(id data)
    {
        self.infoDic = data;
        [self.listV reloadData];

    } error:^(NSError *error) {

    }];
}

-(void)recordRequest
{
    [RequestManager RequstWithUrl:@"/index.php?g=App&m=TeacherCourse&a=studentSignlogs" parmDic:@{@"aid":self.aid,@"page":[NSString stringWithFormat:@"%ld",page]} requestType:RequestGET Success:^(id data)
    {
        self.listArr = data;
        [self.listV reloadData];
    } error:^(NSError *error) {

    }];
}

-(void)BackAct
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
